#pragma once
#include <vector>
#include <string>

using namespace std;

class StringUtil
{
public:
	StringUtil();
	~StringUtil();

	static vector<string> split(const string& s, char delim, int rep = 0);
	static float toFloat(string s);
	static int toInt(string s);
};

StringUtil::StringUtil()
{
}

StringUtil::~StringUtil()
{
}

vector<string> StringUtil::split(const string& s, char delim, int rep) {
	vector<string> flds;
	if (!flds.empty()) flds.clear();  // empty vector if necessary
	string work = s.data();
	string buf = "";
	size_t i = 0;
	while (i < work.length()) {
		if (work[i] != delim)
			buf += work[i];
		else if (rep == 1) {
			flds.push_back(buf);
			buf = "";
		} else if (buf.length() > 0) {
			flds.push_back(buf);
			buf = "";
		}
		i++;
	}
	if (!buf.empty())
		flds.push_back(buf);
	return flds;
}

float StringUtil::toFloat( string s )
{
	return (float)(atof(s.c_str()));
}

int StringUtil::toInt( string s )
{
	return atoi(s.c_str());
}
